package org.bronycorps.mlptss.manager.preferences;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AssetsConfiguration {

	public static class BonusConfiguration {
		private String bombAnimation;
		private String containerAnimation;
		private String moneyAnimation;
		private String shieldBreakerAnimation;

		public BonusConfiguration() {
			super();
		}

		public String getBombAnimation() {
			return this.bombAnimation;
		}

		public String getContainerAnimation() {
			return this.containerAnimation;
		}

		public String getMoneyAnimation() {
			return this.moneyAnimation;
		}

		public String getShieldBreakerAnimation() {
			return this.shieldBreakerAnimation;
		}

		public void setBombAnimation(String bombAnimation) {
			this.bombAnimation = bombAnimation;
		}

		public void setContainerAnimation(String containerAnimation) {
			this.containerAnimation = containerAnimation;
		}

		public void setMoneyAnimation(String moneyAnimation) {
			this.moneyAnimation = moneyAnimation;
		}

		public void setShieldBreakerAnimation(String shieldBreakerAnimation) {
			this.shieldBreakerAnimation = shieldBreakerAnimation;
		}

	}

	public static class BossConfiguration {
		private String animationDefault;
		private String name;

		private BossConfiguration() {
			super();
		}

		public String getAnimationDefault() {
			return this.animationDefault;
		}

		public String getName() {
			return this.name;
		}

		public void setAnimationDefault(String animationDefault) {
			this.animationDefault = animationDefault;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

	public static class BulletConfiguration {
		private String animationName;
		private String name;

		public BulletConfiguration() {
			super();
		}

		public String getAnimationName() {
			return this.animationName;
		}

		public String getName() {
			return this.name;
		}

		public void setAnimationName(String animationName) {
			this.animationName = animationName;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

	public static class CharacterConfiguration {
		private String animationPrefix;
		private String assetAtlas;
		private int attack;
		private String bossName;
		private String bulletTypeName;
		private float chargeSpeed;
		private String name;
		private String specialAttackName;
		private int speed;

		public CharacterConfiguration() {
			super();
		}

		public String getAnimationPrefix() {
			return this.animationPrefix;
		}

		public String getAssetAtlas() {
			return this.assetAtlas;
		}

		public int getAttack() {
			return this.attack;
		}

		public String getBossName() {
			return this.bossName;
		}

		public String getBulletTypeName() {
			return this.bulletTypeName;
		}

		public float getChargeSpeed() {
			return this.chargeSpeed;
		}

		public String getName() {
			return this.name;
		}

		public String getSpecialAttackName() {
			return this.specialAttackName;
		}

		public int getSpeed() {
			return this.speed;
		}

		public void setAnimationPrefix(String animationPrefix) {
			this.animationPrefix = animationPrefix;
		}

		public void setAssetAtlas(String assetAtlas) {
			this.assetAtlas = assetAtlas;
		}

		public void setAttack(int attack) {
			this.attack = attack;
		}

		public void setBossName(String bossName) {
			this.bossName = bossName;
		}

		public void setBulletTypeName(String bulletTypeName) {
			this.bulletTypeName = bulletTypeName;
		}

		public void setChargeSpeed(float chargeSpeed) {
			this.chargeSpeed = chargeSpeed;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setSpecialAttackName(String specialAttackName) {
			this.specialAttackName = specialAttackName;
		}

		public void setSpeed(int speed) {
			this.speed = speed;
		}

	}

	public static class EnemyConfiguration {
		private String animationPrefix;
		private String name;

		public EnemyConfiguration() {
			super();
		}

		public EnemyConfiguration(String name, String animationPrefix) {
			super();
			this.name = name;
			this.animationPrefix = animationPrefix;
		}

		public String getAnimationPrefix() {
			return this.animationPrefix;
		}

		public String getName() {
			return this.name;
		}

		public void setAnimationPrefix(String animationPrefix) {
			this.animationPrefix = animationPrefix;
		}

		public void setName(String name) {
			this.name = name;
		}

	}

	public static class MissileConfiguration {
		private String animationName;

		public MissileConfiguration() {
			super();
		}

		public MissileConfiguration(String animationName) {
			super();
			this.animationName = animationName;
		}

		public String getAnimationName() {
			return this.animationName;
		}

	}

	public static class SpecialAttackConfiguration {
		private String animationName;
		private float duration;
		private boolean exploseOnHit = false;
		private boolean followDirection = false;
		private String name;
		private String script;

		private SpecialAttackConfiguration() {
			super();
		}

		public String getAnimationName() {
			return this.animationName;
		}

		public float getDuration() {
			return this.duration;
		}

		public String getName() {
			return this.name;
		}

		public String getScript() {
			return this.script;
		}

		public boolean isExploseOnHit() {
			return this.exploseOnHit;
		}

		public boolean isFollowDirection() {
			return this.followDirection;
		}

		public void setAnimationName(String animationName) {
			this.animationName = animationName;
		}

		public void setDuration(float duration) {
			this.duration = duration;
		}

		public void setExploseOnHit(boolean exploseOnHit) {
			this.exploseOnHit = exploseOnHit;
		}

		public void setFollowDirection(boolean followDirection) {
			this.followDirection = followDirection;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setScript(String script) {
			this.script = script;
		}

	}

	private ArrayList<AnimationConfiguration> animations = new ArrayList<AnimationConfiguration>();

	private BonusConfiguration bonus = new BonusConfiguration();
	private ArrayList<BossConfiguration> bosses = new ArrayList<BossConfiguration>();
	private transient Map<String, BulletConfiguration> bulletCache = new HashMap<String, AssetsConfiguration.BulletConfiguration>();
	private ArrayList<BulletConfiguration> bullets = new ArrayList<AssetsConfiguration.BulletConfiguration>();
	private ArrayList<CharacterConfiguration> characters = new ArrayList<CharacterConfiguration>();

	private String commonExplosionAnimationName;
	private ArrayList<EnemyConfiguration> enemies = new ArrayList<EnemyConfiguration>();
	private MissileConfiguration missile;

	private transient Map<String, SpecialAttackConfiguration> specialAttackCache = new HashMap<String, SpecialAttackConfiguration>();

	private ArrayList<SpecialAttackConfiguration> specialAttacks = new ArrayList<SpecialAttackConfiguration>();

	public AssetsConfiguration() {
	}

	public List<String> getAllAtlases() {
		List<String> result = new ArrayList<String>();

		for (AnimationConfiguration c : this.animations) {
			result.add(c.getPathName());
		}

		return result;
	}

	public ArrayList<AnimationConfiguration> getAnimations() {
		return this.animations;
	}

	public BonusConfiguration getBonus() {
		return this.bonus;
	}

	public BossConfiguration getBossByName(String bossName) {

		for (BossConfiguration c : this.bosses) {
			if (c.name.equals(bossName)) {
				return c;
			}
		}

		return null;
	}

	public BulletConfiguration getBulletByName(String name) {
		if (this.bulletCache.isEmpty()) {
			for (BulletConfiguration c : this.bullets) {
				this.bulletCache.put(c.name, c);
			}
		}
		return this.bulletCache.get(name);

	}

	public ArrayList<BulletConfiguration> getBullets() {
		return this.bullets;
	}

	public ArrayList<CharacterConfiguration> getCharacters() {
		return this.characters;
	}

	public CharacterConfiguration getCharByName(String name) {
		for (CharacterConfiguration c : this.characters) {
			if (c.getName().equals(name)) {
				return c;
			}
		}
		return null;
	}

	public String getCommonExplosionAnimationName() {
		return this.commonExplosionAnimationName;
	}

	public ArrayList<EnemyConfiguration> getEnemies() {
		return this.enemies;
	}

	public EnemyConfiguration getEnemyByName(String name) {
		for (EnemyConfiguration c : this.enemies) {
			if (c.getName().equals(name)) {
				return c;
			}
		}
		return null;
	}

	public MissileConfiguration getMissile() {
		return this.missile;
	}

	public SpecialAttackConfiguration getSpecialAttackByName(String name) {
		if (this.specialAttackCache.isEmpty()) {
			for (SpecialAttackConfiguration c : this.specialAttacks) {
				this.specialAttackCache.put(c.name, c);
			}
		}
		return this.specialAttackCache.get(name);

	}

	public ArrayList<SpecialAttackConfiguration> getSpecialAttacks() {
		return this.specialAttacks;
	}

	public void setCommonExplosionAnimationName(
			String commonExplosionAnimationName) {
		this.commonExplosionAnimationName = commonExplosionAnimationName;
	}

}
